package com.lwm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwm.domain.ReplenishmentApproval;
import com.lwm.domain.ResponseResult;
import com.lwm.dto.PageParams;
import com.lwm.mapper.ReplenishmentApprovalMapper;
import com.lwm.service.ReplenishmentApprovalService;
import com.lwm.utils.Code;
import com.lwm.utils.HintMessage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 补货申请表(ReplenishmentApproval)表服务实现类
 *
 * @author lzl
 * @since 2023-10-17 18:11:13
 */
@Service("replenishmentApprovalService")
public class ReplenishmentApprovalServiceImpl implements ReplenishmentApprovalService {
    @Resource
    private ReplenishmentApprovalMapper replenishmentApprovalMapper;


    @Override
    public ResponseResult<ReplenishmentApproval> getById(Long id) {
        ReplenishmentApproval replenishmentApproval = replenishmentApprovalMapper.getById(id);
        return new ResponseResult<>(Code.GET_OK, HintMessage.GET_OK_HINT, replenishmentApproval);
    }

    @Override
    public ResponseResult<PageInfo<ReplenishmentApproval>> page(ReplenishmentApproval replenishmentApproval, PageParams pageParams) {
        PageInfo<ReplenishmentApproval> pageInfo = PageHelper.startPage(pageParams.getPage(), pageParams.getSize())
                .doSelectPageInfo(() -> replenishmentApprovalMapper.getPage(replenishmentApproval));
        return new ResponseResult<>(Code.GET_OK, HintMessage.GET_OK_HINT, pageInfo);
    }

    @Override
    public ResponseResult update(ReplenishmentApproval replenishmentApproval) {
        if (replenishmentApproval == null || replenishmentApproval.getId() == null) return new ResponseResult(Code.UPDATE_ERR, HintMessage.EDIT_LACK_ID);
        replenishmentApprovalMapper.update(replenishmentApproval);
        return new ResponseResult(Code.UPDATE_OK, HintMessage.EDIT_OK_HINT);
    }
}
